package com.allqj.sfx.ddd.member.infrastructure.converter;

import com.allqj.sfx.ddd.member.domain.entity.flow.FlowInstanceTask;
import com.allqj.sfx.ddd.member.infrastructure.dao.FlowInstanceTaskDAO;
import com.allqj.sfx.ddd.member.infrastructure.po.FlowInstanceTaskDO;
import com.allqj.sfx.infrastructure.converter.DataConverter;
import com.allqj.sfx.infrastructure.utils.JsonUtil;
import com.google.gson.reflect.TypeToken;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * @author sjw
 * @className FlowInstanceTaskConverter
 * @date 2022/7/21 9:30
 * @description: FlowInstanceTask&FlowInstanceTaskDO转换器
 */
public class FlowInstanceTaskConverter implements DataConverter<FlowInstanceTask, FlowInstanceTaskDO, FlowInstanceTaskDAO> {

    // 转换器实例
    public static FlowInstanceTaskConverter INSTANCE = new FlowInstanceTaskConverter();


    @Override
    public FlowInstanceTask do2Entity(FlowInstanceTaskDO flowInstanceTaskDO) {
        if (flowInstanceTaskDO == null) return null;
        FlowInstanceTask flowInstanceTask = new FlowInstanceTask();
        BeanUtils.copyProperties(flowInstanceTaskDO, flowInstanceTask);
        flowInstanceTask.setApproverDef(JsonUtil.jsonToObject(flowInstanceTaskDO.getApproverDef(), new TypeToken<List<Integer>>() {
        }.getType()));
        return flowInstanceTask;
    }

    @Override
    public FlowInstanceTaskDO entity2Do(FlowInstanceTask flowInstanceTask) {
        if (flowInstanceTask == null) return null;
        FlowInstanceTaskDO flowInstanceTaskDO = new FlowInstanceTaskDO();
        BeanUtils.copyProperties(flowInstanceTask, flowInstanceTaskDO);
        flowInstanceTaskDO.setApproverDef(JsonUtil.objectToJson(flowInstanceTask.getApproverDef()));
        return flowInstanceTaskDO;
    }

    @Override
    public FlowInstanceTaskDO entity2Do(FlowInstanceTask flowInstanceTask, FlowInstanceTaskDAO dao) {
        return null;
    }
}
